package com.oocl.batchdatav2.command.receiver;

import com.oocl.batchdatav2.action.DataProcessAction;
import com.oocl.batchdatav2.command.BaseReceiver;
import com.oocl.batchdatav2.comparator.BirthdayComparator;
import com.oocl.batchdatav2.comparator.IdComparator;
import com.oocl.batchdatav2.processor.DataProcessor;
import com.oocl.batchdatav2.processor.impl.DataProcessorImpl;

public class ListCommandReceiver extends BaseReceiver {
	
	private DataProcessor dataProcessor;
	private DataProcessAction action = DataProcessAction.INSTANCE;

	public ListCommandReceiver(String[] commandSplit) {
		super(commandSplit);
		dataProcessor = new DataProcessorImpl(action.customerListStore);
	}

	@Override
	public StringBuilder action() {
		if (commandSplit.length != 3) {
			return new StringBuilder("L command error.");
		}
		
		String format = commandSplit[1];
		String sortBy = commandSplit[2];
		
		switch (sortBy) {
		case "id":
			return dataProcessor.process(new IdComparator(), format);
		case "birth":
			return dataProcessor.process(new BirthdayComparator(), format);
		default:
			return new StringBuilder("L command error.");
		}
		
	}

}
